package com.whiteape.book.model.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.whiteape.book.utils.MapConverter;
import java.util.HashMap;

import com.whiteape.book.model.dto.SiteSourceHomepageBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SITE_SOURCE_HOMEPAGE_BEAN".
*/
public class SiteSourceHomepageBeanDao extends AbstractDao<SiteSourceHomepageBean, String> {

    public static final String TABLENAME = "SITE_SOURCE_HOMEPAGE_BEAN";

    /**
     * Properties of entity SiteSourceHomepageBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", true, "ID");
        public final static Property SiteHostUrl = new Property(1, String.class, "siteHostUrl", false, "SITE_HOST_URL");
        public final static Property HeadName = new Property(2, String.class, "headName", false, "HEAD_NAME");
        public final static Property UpdateTime = new Property(3, String.class, "updateTime", false, "UPDATE_TIME");
        public final static Property DetailUrl = new Property(4, String.class, "detailUrl", false, "DETAIL_URL");
        public final static Property VarMap = new Property(5, String.class, "varMap", false, "VAR_MAP");
    }

    private final MapConverter varMapConverter = new MapConverter();

    public SiteSourceHomepageBeanDao(DaoConfig config) {
        super(config);
    }
    
    public SiteSourceHomepageBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SITE_SOURCE_HOMEPAGE_BEAN\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: id
                "\"SITE_HOST_URL\" TEXT," + // 1: siteHostUrl
                "\"HEAD_NAME\" TEXT," + // 2: headName
                "\"UPDATE_TIME\" TEXT," + // 3: updateTime
                "\"DETAIL_URL\" TEXT," + // 4: detailUrl
                "\"VAR_MAP\" TEXT);"); // 5: varMap
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_SITE_SOURCE_HOMEPAGE_BEAN_SITE_HOST_URL ON \"SITE_SOURCE_HOMEPAGE_BEAN\"" +
                " (\"SITE_HOST_URL\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SITE_SOURCE_HOMEPAGE_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SiteSourceHomepageBean entity) {
        stmt.clearBindings();
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }
 
        String siteHostUrl = entity.getSiteHostUrl();
        if (siteHostUrl != null) {
            stmt.bindString(2, siteHostUrl);
        }
 
        String headName = entity.getHeadName();
        if (headName != null) {
            stmt.bindString(3, headName);
        }
 
        String updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindString(4, updateTime);
        }
 
        String detailUrl = entity.getDetailUrl();
        if (detailUrl != null) {
            stmt.bindString(5, detailUrl);
        }
 
        HashMap varMap = entity.getVarMap();
        if (varMap != null) {
            stmt.bindString(6, varMapConverter.convertToDatabaseValue(varMap));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SiteSourceHomepageBean entity) {
        stmt.clearBindings();
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }
 
        String siteHostUrl = entity.getSiteHostUrl();
        if (siteHostUrl != null) {
            stmt.bindString(2, siteHostUrl);
        }
 
        String headName = entity.getHeadName();
        if (headName != null) {
            stmt.bindString(3, headName);
        }
 
        String updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindString(4, updateTime);
        }
 
        String detailUrl = entity.getDetailUrl();
        if (detailUrl != null) {
            stmt.bindString(5, detailUrl);
        }
 
        HashMap varMap = entity.getVarMap();
        if (varMap != null) {
            stmt.bindString(6, varMapConverter.convertToDatabaseValue(varMap));
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public SiteSourceHomepageBean readEntity(Cursor cursor, int offset) {
        SiteSourceHomepageBean entity = new SiteSourceHomepageBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // siteHostUrl
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // headName
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // updateTime
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // detailUrl
            cursor.isNull(offset + 5) ? null : varMapConverter.convertToEntityProperty(cursor.getString(offset + 5)) // varMap
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SiteSourceHomepageBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setSiteHostUrl(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setHeadName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setUpdateTime(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setDetailUrl(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setVarMap(cursor.isNull(offset + 5) ? null : varMapConverter.convertToEntityProperty(cursor.getString(offset + 5)));
     }
    
    @Override
    protected final String updateKeyAfterInsert(SiteSourceHomepageBean entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(SiteSourceHomepageBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SiteSourceHomepageBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
